<template>
	<el-dialog :title="(addType=='before'?'前':'后')+'加签对话框'" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-position="left">
			<el-form-item label="人员选择">
				<select-user-for-bpm v-model:accountId="form.accountId"
									 ref="selectUserOtherUserDialog"
									 :temp-org-id="tempOrgId"
									 :step-id="stepId"
									 :default-value-s="form.accountId"
									 el-field-s="accountId"
									 change-user="1"
									 mode-s="multiple"
				></select-user-for-bpm>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">加 签</el-button>
		</template>
	</el-dialog>
</template>
<script>
import selectUserForBpm from "@/views/module/selectUserForBpm";
import useTabs from '@/utils/useTabs'
export default {
	components: {
		selectUserForBpm
	},
	props: {
		tempOrgId: String,
		stepId: String,
		stepRunId: String,
	},
	data(){
		return{
			visible: false,
			isSaveing: false,
			addType:'before',
			form:{
				accountId:'',
				stepRunId:this.stepRunId
			}
		}
	},
	methods:{
		open(addType) {
			this.addType = addType;
			this.visible = true;
			return this
		},
		async submit() {
			var res;
			if(this.addType=="before")
			{
				res= await this.$API.bpm.bpmStepRun.addBeforeBpmStepRun.post(this.form);
			}else if(this.addType=="after")
			{
				res = await this.$API.bpm.bpmStepRun.addAfterBpmStepRun.post(this.form);
			}
			if (res.code == 200) {
				this.$message.success("加签成功");
				useTabs.close();
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
	}
}
</script>
